<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>Document</title>
    <script>
        function login() {
            console.log("登陆")
            var name = document.getElementById("username").value
            var xmlHttp = new XMLHttpRequest()
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                    var response = JSON.parse(xmlHttp.responseText)
                    console.log(response)
                    if (response.data) {
                        sessionStorage.setItem("loginUser", JSON.stringify(response.data))
                        window.location.href = "/index.html"
                    } else alert('登陆失败')
                }
            }
            xmlHttp.open("GET", "/api/login?name=" + name, true)
            xmlHttp.send();
        }
    </script>
</head>
<body>
    <h1>登陆</h1>
    <input id="username" value=""/>
    <input type="button" value="登陆" onclick="login()"/>
</body>
</html>